package Engine.RMI
{
	import Engine.flash.*;
	import Framework.Serialize.*;
	import Framework.Util.*;
	
	public class RMIObject extends EventSender
	{
		protected var _response:Function;
		protected var _ex:Function;
		private var _identity:SIdentity;
		private var _callFunction:String;
		private var _usedTimer:Number;
		public var userObject:Object;
		
		public function RMIObject(response:Function = null, ex:Function = null)
		{
			this._response = response;
			this._ex = ex;
		}
		
		public function __dispatch(context:Context, call:SRMICall, stream:SerializeStream, streams:SerializeStream) : ERMIDispatchStatus
		{
			return ERMIDispatchStatus.DispatchOK;
		}
		
		public function __response(param1:SerializeStream) : void
		{
		}
		
		public function cdeException(exception:Exception) : void
		{
			if (this._ex != null)
			{
				this._ex.call(this, exception);
				
			}
			exception.method = "";
			if (this._identity)
			{
				exception.method = this._identity.name + ":";
			}
			else
			{
				trace("method:" + exception.method + " callFunction:" + this._callFunction);
			}
			exception.method = exception.method + this._callFunction;
			RMIDispatcher.getInstance().dispatchErrorEvent(exception);
		}
		
		public function get identity() : SIdentity
		{
			return this._identity;
		}
		
		public function set identity(identity:SIdentity) : void
		{
			if (this._identity == null)
			{
				this._identity = new SIdentity();
			}
			this._identity.name = identity.name;
		}
		
		public function set name(name:String) : void
		{
			if (this._identity == null)
			{
				this._identity = new SIdentity();
			}
			this._identity.name = name;
		}
		
		public function get name() : String
		{
			if (this._identity)
			{
				return this._identity.name;
			}
			return null;
		}
		
		public function set callFunction(callFunction:String) : void
		{
			this._callFunction = callFunction;
		}
		
		public function get usedTimer() : Number
		{
			return this._usedTimer;
		}
		
		public function set usedTimer(usedTimer:Number) : void
		{
			this._usedTimer = usedTimer;
		}
		
		public function get callFunction() : String
		{
			return this._callFunction;
		}
	}
}
